import axios from 'axios';
import Loading from "../components/loading";
import { Imyreq } from '../interface';
import Alymodel from '../mysql_interface/model';
import { default as Study, default as Studycodemodel } from '../mysql_interface/studycodemodel';
import TuyaiotModel from '../mysql_interface/tuyaiotmodel';
import { testHostname } from '../util/data';
import Tracker from './Tracker';
import * as api from './interface';
export interface Apimatchuserquestion {
  userquestion: Study.Imatchuserquestion[],
  user: Study.Iuser[],
  question: Study.Iquestion[],
  activity: Study.Iactivity,
  team: Study.Iteam[],
  teamuser: Study.Iteamuser[]
}

interface Imsg extends String {
  data: any
}



interface Iapi<T> {
  error: number,
  msg?: Imsg,
  data: T
}

type KS<T> = keyof T

export type Iobj<T = any> = {
  [key in keyof T]?: any;
} & {
  _limit?: number;
  _offset?: number;
  _order?: keyof T | string[];
  _sortable?: 'DESC' | 'ASC';
  _like?: [keyof T, any] | Array<[keyof T, any]>;
  _include?: {
    [key in keyof T]: [string, any]
  },
  _keyword?: Array<[string, string]>,
  _json?: {
    field: string, path: string, value: any, operator?: 'contains' | 'like' | '='
  }[]
  tenant_id?: string | null
};

export type Iteamobj<T = any> = {
  [key in keyof T]?: any;
} & {
  teamid: number
  _limit?: number;
  _offset?: number;
  _order?: keyof T;
  _sortable?: 'DESC' | 'ASC';
  _like?: [keyof T, any] | Array<[keyof T, any]>;
  _include?: {
    [key in keyof T]: [string, any]
  }
};

export interface IID extends Iobj {
  ID: number | string
}
export interface TeamIID extends Iobj {
  ID: number | string
  teamid: number | string
}

const logs = ["/studycode/v1/sys/getactivity", "/studycode/v1/sys/getquestion", "/studycode/v1/sys/getquestionbank", "/studycode/v1/user/changeactivityuser", "/studycode/v1/user/savematchuserdata", "/studycode/v2/team/getactivity"]

const config = {
  xsrfCookieName: 'csrfToken',
  xsrfHeaderName: 'x-csrf-token',
  // baseURL: process.env.baseURL || process.env.apiUrl || ""
  // timeout: 60 * 1000, // Timeout
  // withCredentials: true, // Check cross-site Access-Control
};
export const _axios = axios.create(config);

export function jilurizhi(arr: [string, any][]) {
  // 测试服 不记录日志 
  if (window.location.hostname === testHostname) {
    console.log("测试服不记录日志")
    return
  }

  if (process.env.NODE_ENV === 'production') {
    const host = 'cn-qingdao.log.aliyuncs.com';
    const project = 'htetest1';
    const logstore = 'ojhte';
    const log = new Tracker(host, project, logstore);
    log.push('_userid_', window._userid_)
    log.push('_username_', window._username_)
    log.push('_teams_', window._teams_)
    log.push('_phonenum_', window._phonenum_)
    log.push('_teams_', window._teams_)
    log.push('_teamids_', window._teamids_)
    log.push('_cid_', window._cid_);

    for (const v of arr) {
      log.push(v[0], v[1])
    }
    if (window._userid_) {
      log.logger()
    }
  }
}

export function fetchapi<T, R = {}>(input: string, body?: R) {
  Loading.addloadings()
  const host = 'cn-qingdao.log.aliyuncs.com';
  const project = 'htetest1';
  const logstore = 'ojhte';
  const t = Date.now()
  const log = new Tracker(host, project, logstore);
  log.push('_userid_', window._userid_)
  log.push('_username_', window._username_)
  log.push('_teams_', window._teams_)
  log.push('_teamids_', window._teamids_)
  log.push('_teamidarr_', window._teamidarr_)
  log.push('_phonenum_', window._phonenum_)
  log.push('_method_', input);
  log.push('_cid_', window._cid_);
  log.push('type', 'fetch');
  try {
    const d = JSON.stringify(body)
    if (d && d.length < 1000) {
      log.push('body', JSON.stringify(body));
    }
  } catch (e: any) {
  }

  const arr = document.cookie.split(';')
  let csrf = ''
  for (const v in arr) {
    const to = arr[v].split('=');
    if (to[0].replace(/\s+/g, "") === "csrfToken") {
      csrf = to[1].replace(/\s+/g, "")
    }
  }

  if (!window.fetch === false) {
    return new Promise<T>((res, rej) => {
      fetch('/api' + input, {
        cache: 'no-cache',
        headers: {
          'content-type': 'application/json',
          'x-csrf-token': csrf
        },
        method: 'POST',
        body: JSON.stringify(body)
      }).then((res) => {
        log.push('status', res.status);
        log.push('time', Date.now() - t);
        log.push('size', res.headers.get('content-length'));
        return res.json()
      }).then((body: Iapi<T>) => {
        Loading.removeloadings()
        const { data, error, msg } = body
        if (error) {
          log.push('_error_', error);
          if (msg && data) {
            rej({ data, toString: () => msg })
          }
          rej(msg)
        } else {
          if (logs.includes(input) && data && typeof data === 'object' && !Array.isArray(data)) {
            const d = data as unknown as any
            log.push('typename1', d['name'] ? d['name'] : '');
          }
          res(data)
        }
        if (process.env.NODE_ENV === 'production') {
          if (window._userid_) {
            log.logger()
          }
        }
      }).catch(e => {
        Loading.removeloadings()
        log.push('_error_', e);
        if (process.env.NODE_ENV === 'production') {
          if (window._userid_) {
            log.logger()
          }
        }
        rej(e)
      })
    })
  } else {
    return new Promise<T>((res, rej) => {
      _axios.post('/api' + input, body).then(({ data }) => {
        if (data.error) {
          const msg = data.msg
          msg.data = data.data
          rej(msg)
        } else {
          res(data.data)
        }
        Loading.removeloadings()
      }).catch(() => {
        rej('服务器出错')
        Loading.removeloadings()
      })
    })
  }

}

export async function online() {
  try {
    const { data } = await axios.get<{ error: number, data: Study.Iuser, msg: string }>('/api' + api.online)
    if (data.error === 0) {
      window._userid_ = data.data.ID
      window._username_ = data.data.name
      window._phonenum_ = data.data.phonenum
      window._cid_ = data.data.gid
      return data.data
    } else {
      return Promise.reject(data.msg)
    }
  } catch (e: any) {
    return Promise.reject(e)
  }
}

export function offline() {
  window._userid_ = undefined
  window._username_ = undefined
  return fetchapi<Study.Iuser>(api.offline)
}

export function asynclogin(body: { ID: number | string, password?: string, yzm?: string, teamid?: string }) {
  return fetchapi<Study.Iuser>(api.login, body)
}

export function asyncgetuser(body: IID) {
  return fetchapi<Study.Iuser>(api.getuser, body)
}
export function asyncselectuser(body?: Iobj<Study.Iuser>) {
  return fetchapi<Imyreq<Study.Iuser>>(api.selectuser, body)
}


export function asyncadmincreateorupdateuser(body: Study.Iuser) {
  return fetchapi<Study.Iuser>(api.admincreateorupdateuser, body)
}

export function asynccreateorupdateactivity(body: { data: Study.Iactivity, users: Studycodemodel.Iuser[], question: Studycodemodel.Imatchquestion[], tenant_id?: string | null, }) {
  if (!body.data.customerserviceid) {
    (body.data.customerserviceid as any) = null
  }
  return fetchapi<Study.Iactivity>(api.createorupdateactivity, body)
}
export function asyncgetactivity(body: IID) {
  return fetchapi<Study.Iactivity>(api.getactivity, body)
}
export function asyncTeamGetActivity(body?: Iobj<Study.Iactivity>) {
  return fetchapi<Study.Iactivity>(api.teamGetActivity, body)
}
export function asyncadmingetactivity(body: IID) {
  return fetchapi<Study.Iactivity>(api.admingetactivity, body)
}
export function asyncselectactivity(body?: Iobj<Study.Iactivity>) {
  return fetchapi<{
    rows: Study.Iactivity[], count: number;
  }>(api.selectactivity, body)
}

export function asyncadminselectactivity(body?: Iobj<Study.Iactivity>) {
  return fetchapi<{
    rows: Study.Iactivity[], count: number;
  }>(api.adminselectactivity, body)
}

export function asyncdelactivity(body: IID) {
  return fetchapi<Study.Iactivity>(api.delactivity, body)
}
// 管理员删除比赛
export function asyncadmindelactivity(body: IID) {
  return fetchapi<Study.Iactivity>(api.admindelactivity, body)
}

// 管理员复制比赛
export function asyncadmincopyactivity(body: IID) {
  return fetchapi<Study.Iactivity>(api.admincopyactivity, body)
}
// 教师复制
export function asyncTeamCopyActivity(body: TeamIID) {
  return fetchapi<Study.Iactivity>(api.teamCopyActivity, body)
}
export function asyncTeamCopyTeamJob(body: TeamIID) {
  return fetchapi<Study.Iactivity>(api.teamCopyTeamJob, body)
}



export function asynccreateorupdatearticle(body: Study.Iarticle) {
  return fetchapi<Study.Iarticle>(api.createorupdatearticle, body)
}
export function asyncgetarticle(body: IID) {
  return fetchapi<Study.Iarticle>(api.getarticle, body)
}
export function asyncselectarticle(body?: Iobj<Study.Iarticle>) {
  return fetchapi<Study.Iarticle[]>(api.selectarticle, body)
}
export function asyncdelarticle(body: IID) {
  return fetchapi<Study.Iarticle>(api.delarticle, body)
}
export function asynccreateorupdatequestion(body: Study.Iquestion) {
  return fetchapi<Study.Iquestion>(api.createorupdatequestion, body)
}
export function asyncadmincreateorupdatequestion(body: Study.Iquestion) {
  return fetchapi<Study.Iquestion>(api.admincreateorupdatequestion, body)
}
export function asyncgetquestion(body: IID) {
  return fetchapi<Study.Iquestion>(api.getquestion, body)
}
interface Iquestionext extends Study.Iquestion {
  ACcount?: number
  userquestioncount?: number
}

export interface Iquestionoption extends Study.Iquestion {
  activityid?: number
  jobid?: number
}

export function asyncselectquestion(body?: Iobj<Iquestionoption>) {
  return fetchapi<{ count: number, rows: Iquestionext[] }>(api.selectquestion, body)
}
export function asyncdelquestion(body: IID) {
  return fetchapi<Study.Iquestion>(api.delquestion, body)
}
export function asynccreateorupdatequestionbank(body: Study.Iquestionbank) {
  return fetchapi<Study.Iquestionbank>(api.createorupdatequestionbank, body)
}
export async function asyncgetquestionbank(body: IID) {
  const data = await fetchapi<Study.Iquestionbank>(api.getquestionbank, body)
  const questionquestionbank = data.questionquestionbank?.sort(
    (a, b) => Number(a.sortindex) - Number(b.sortindex)
  );
  return Object.assign(data, { questionquestionbank })
}
export function asyncselectquestionbank(body?: Iobj<Study.Iquestionbank>) {
  return fetchapi<{ rows: Study.Iquestionbank[], count: number }>(api.selectquestionbank, body)
}
export function asyncdelquestionbank(body: { ID: number }) {
  return fetchapi<Study.Iquestionbank>(api.delquestionbank, body)
}

export function asynccreateorupdatelabel(body: Study.ILabel) {
  return fetchapi<Study.ILabel>(api.createorupdatelabel, body)
}
export function asyncgetlabel(body: IID) {
  return fetchapi<Study.ILabel>(api.getlabel, body)
}
export function asyncselectlabel(body?: Iobj<Study.ILabel>) {
  return fetchapi<{ rows: Study.ILabel[], count: number }>(api.selectlabel, body)
}
export function asyncdellabel(body: IID) {
  return fetchapi<Study.ILabel>(api.dellabel, body)
}
export const ossupload = function () {
  return fetchapi<{
    accessKeyId: string;
    accessKeySecret: string;
    expiration: string;
    securityToken: string;
  }>(api.ossupload)
}

export const asyncselecmyuserquestion = function (body?: IID) {
  return fetchapi<Study.ILabel>(api.selecmyuserquestion, body)
}

export const asyncgetregistphoneVerificationCode = function (phonenum: string | number) {
  return fetchapi(api.getregistphoneVerificationCode, { phonenum })
}

export const asyncresetpassword = function (body: { phonenum: string, yzm: string, password: string }) {
  return fetchapi(api.resetpassword, body)
}

export const asyncruncode = function (body: { context: string, language: string, textarea: string, questionid: number, questionbankid?: number, run?: boolean, ismatch?: boolean }) {
  return fetchapi(api.runcode, body)
}

export const asyncchangefabulouscomment = function (body: { questioncommentid: number }) {
  return fetchapi(api.changefabulouscomment, body)
}

export const asynccreatequestioncomment = function (body: { pid: number, context: string, htmlcontext: string, questionid: number, questionname?: string, questionbankname?: string, text?: string }) {
  return fetchapi(api.createquestioncomment, body)
}

export const asyncadmincreatequestioncomment = function (body: Study.Iquestioncomment) {
  return fetchapi(api.admincreatequestioncomment, body)
}

export const asyncgetfabulouscomment = function (body: Iobj<Study.Iquestioncomment>) {
  return fetchapi<{ count: number, rows: Study.Iquestioncomment[] }>(api.getfabulouscomment, body)
}

export const asyncadmingetfabulouscomment = function (body: Iobj<Study.Iquestioncomment>) {
  return fetchapi<{ count: number, rows: Study.Iquestioncomment[] }>(api.admingetfabulouscomment, body)
}

export const asyncadmindelfabulouscomment = function (body: Iobj<Study.Iquestioncomment>) {
  return fetchapi<{ count: number, rows: Study.Iquestioncomment[] }>(api.admindelfabulouscomment, body)
}

export const asyncaadminupdatefabulouscomment = function (body: Study.Iquestioncomment) {
  return fetchapi(api.adminupdatefabulouscomment, body)
}



export const asyncgetmatchcomment = function (body: Iobj<Study.Iquestioncomment>) {
  return fetchapi<{ count: number, rows: Study.Iquestioncomment[] }>(api.getmatchcomment, body)
}

export const asyncadmingetmatchcomment = function (body: Iobj<Study.Iquestioncomment>) {
  return fetchapi<{ count: number, rows: Study.Iquestioncomment[] }>(api.admingetmatchcomment, body)
}

export const asyncadmindelmatchcomment = function (body: Iobj<Study.Iquestioncomment>) {
  return fetchapi<{ count: number, rows: Study.Iquestioncomment[] }>(api.admindelmatchcomment, body)
}

export const asyncaadminupdatematchcomment = function (body: Study.Iquestioncomment) {
  return fetchapi(api.adminupdatematchcomment, body)
}


export const asyncgetusercount = function (body?: Study.Iuser) {
  return fetchapi(api.getusercount, body)
}

export const asyncgetquestioncount = function (body?: Study.Iquestion) {
  return fetchapi(api.getquestioncount, body)
}

export const asyncgetactivitycount = function (body?: Study.Iactivity) {
  return fetchapi(api.getactivitycount, body)
}

export const asyncgetarticlecount = function (body?: Study.Iarticle) {
  return fetchapi(api.getarticlecount, body)
}

export const asyncgetquestionbankcount = function (body?: Study.Iquestionbank) {
  return fetchapi(api.getquestionbankcount, body)
}

export const asyncgetlabelcount = function (body?: Study.ILabel) {
  return fetchapi(api.getlabelcount, body)
}

export const asyncchangequestionquestionbank = function (body?: { questionbankid: number, list?: Study.Iquestionquestionbank[] }) {
  return fetchapi(api.changequestionquestionbank, body)
}

export const asyncadminselectuserquestion = function (body?: Iobj<Study.Iuserquestion>) {
  return fetchapi<{ count: number, rows: Study.Iuserquestion[] }>(api.adminselectuserquestion, body)
}

export const asyncselectuserquestion = function (body?: Iobj<Study.Iuserquestion>) {
  return fetchapi<{ count: number, rows: Study.Iuserquestion[] }>(api.selectuserquestion, body)
}
// 查询已完成题目
export const asyncselectdistinctuserquestion = function (body?: Iobj<Study.Iuserquestion>) {
  return fetchapi<{
    count: { count: number, questionid: number, }[],
    rows: { questionid: number, userid: number, question: Study.Iquestion }[]
  }
  >(api.selectdistinctuserquestion, body)
}


export const asyncselectuserquestionbank = function (body?: Study.Iuserquestion) {
  return fetchapi<Study.Iuser[]>(api.selectuserquestionbank, body)
}

export const asyncchangesetup = function (body?: Study.Isetup) {
  return fetchapi<Study.Isetup>(api.changesetup, body)
}

export const asyncgetsetup = function () {
  return fetchapi<Study.Isetup>(api.getsetup)
}

export const asynclogout = function () {
  return fetchapi(api.logout)
}

export const asyncuserregist = function (body: { phonenum: string, yzm: string, name: string, password?: string, teamid?: string | number | null }) {
  return fetchapi(api.userregist, body)
}
export const asyncHdbmUserRegist = function (body: { phonenum: string, yzm: string, name: string, password?: string, teamid?: string | number | null }) {
  return fetchapi(api.hdbmUserRegist, body)
}

export const asyncchangeuser = function (body: Study.Iuser) {
  return fetchapi(api.changeuser, body)
}

export const asyncchangeactivityuser = function (body: Study.Iactivityuser) {
  return fetchapi(api.changeactivityuser, body)
}

interface teams extends Study.Iteam {
  phonenum?: boolean
}

export const asyncselectteams = function (body?: Iobj<teams>) {
  return fetchapi<Imyreq<Study.Iteam>>(api.selectteams, body)
}
export const asyncselectteamuser = function (body: Iobj<Study.Iteamuser>) {
  return fetchapi<Imyreq<Study.Iteamuser>>(api.selectteamuser, body)
}


export const asyncselectteamquestionbank = function (body: { teamid: number }) {
  return fetchapi<Study.Iquestionbank[]>(api.selectteamquestionbank, body)
}

export const asyncselectteamquestion = function (body: { teamid: number }) {
  return fetchapi<Study.Iquestion[]>(api.selectteamquestion, body)
}

export const asyncadmincreatorupdateteam = function (body: Study.Iteam) {
  return fetchapi<Study.Iteam>(api.admincreatorupdateteam, body)
}

export const asyncadminaddteamuser = function (body: Study.Iteamuser) {
  return fetchapi<Study.Iteamuser>(api.adminaddteamuser, body)
}

// 创建团队用户组
export const asyncadminaddteamusergroup = function (body: Study.Iteamusergroup) {
  return fetchapi<Study.Iteamusergroup>(api.adminaddteamusergroup, body)
}

// 删除团队组
export const asyncadmindelteamusergroup = function (body: { ID: number }) {
  return fetchapi(api.admindelteamusergroup, body)
}

// 查看团队组
export const asyncfindteamusergroup = function (body: { teamid: number }) {
  return fetchapi<Study.Iteamusergroup[]>(api.findteamusergroup, body)
}

// 删除团员
export const asyncadmindelteamuser = function (body: { ID: number }) {
  return fetchapi(api.admindelteamuser, body)
}

export const asyncadmindelteam = function (body: { ID: number }) {
  return fetchapi(api.admindelteam, body)
}

// 查看比赛题目
export const asyncselectmatchquestion = function (body: { activityid: number }) {
  return fetchapi<Study.Imatchquestionbank[]>(api.selectmatchquestion, body)
}
// 提交比赛代码
export const asyncSaveMatch = function (body: { activityid: number, data: any[], userid: number }) {
  return fetchapi<Study.Imatchquestionbank[]>(api.savematch, body)
}

export const asyncadminselectmatchquestion = function (body: Iobj<{ activityid: number }>) {
  return fetchapi<Imyreq<Study.Imatchquestion>>(api.adminselectmatchquestion, body)
}

// 修改管理员比赛题目
export const asyncadminchangematchquestion = function (body: { activityid: number, question: Study.Imatchquestion[] }) {
  return fetchapi<undefined>(api.adminchangematchquestion, body)
}



export const asyncselectmatchuserquestion = function (body: { ID: number, my?: boolean }) {
  return fetchapi<Apimatchuserquestion>(api.selectmatchuserquestion, body)
}

export const asyncadminselectmatchuserquestion = function (body: Iobj<{ activityid: number, type: string }>) {
  return fetchapi<Imyreq<Apimatchuserquestion>>(api.adminselectmatchuserquestion, body)
}
export const asyncAdminUpdateMatchUserQuestion = function (body: Apimatchuserquestion) {
  return fetchapi<Imyreq<Apimatchuserquestion>>(api.adminUpdateMatchUserQuestion, body)
}

export const asyncsavetmpmatchuserdata = function (body: { activityid: number | string, data: any, seconds: number }) {
  return fetchapi(api.savetmpmatchuserdata, body)
}


export const asyncgettmpmatchuserdata = function (body: { activityid: number | string }) {
  return fetchapi(api.gettmpmatchuserdata, body)
}

export const asyncfindcountmatchquestion = function (body: { questionbankid: number }) {
  return fetchapi<number>(api.findcountmatchquestion, body)
}

export const asyncdelmatchuserquestion = function (body: { userid: number, activityid: number }) {
  return fetchapi<number>(api.delmatchuserquestion, body)
}
export const asyncdelTeamMatchUserQuestion = function (body: { teamid: number, userid: number, activityid: number }) {
  return fetchapi<number>(api.delTeamMatchUserQuestion, body)
}

export const asyncadminselectquestionbank = function (body?: Iobj<Study.Iquestionbank>) {
  return fetchapi<Study.Iquestionbank[]>(api.adminselectquestionbank, body)
}


export const asynccreateteam = function (body: { name: string }) {
  return fetchapi<Study.Iteam>(api.createteam, body)
}

export const asyncaddteamlog = function (body: Study.Iteamlog) {
  return fetchapi<Study.Iteamlog>(api.addteamlog, body)
}

export const selecteamtteams = function (body?: Study.Iteam) {
  return fetchapi<Imyreq<Study.Iteam>>(api.selecteamtteams, body)
}

export const asyncgetteam = function (body: { ID?: number, teamkey?: string }) {
  return fetchapi<Study.Iteam>(api.getteam, body)
}

export const asyncteamselectteamlog = function (body: Iobj<Study.Iteamlog>) {
  return fetchapi<Study.Iteamlog[]>(api.teamselectteamlog, body)
}

export const asyncteamselecttask = function (body: Iobj<Study.Iteamtask>) {
  return fetchapi<Imyreq<Study.Iteamtask>>(api.teamselectselecttask, body)
}
interface _Tu extends Study.Iteamuser { phonenum?: boolean, gid?: boolean }
export const asyncselectteamselectuser = function (body: Iobj<_Tu>) {
  return fetchapi<Study.Iteamuser[]>(api.teamselectselectuser, body)
}

export const asyncteamchangeteam = function (body: Study.Iteam) {
  return fetchapi<Study.Iteam>(api.teamchangeteam, body)
}
export const asyncChangeonlineteamid = function (body: { teamid: number | undefined }) {
  return fetchapi<Study.Iteam>(api.changeonlineteamid, body)
}

export const asyncteamaddteamlog = function (body: Study.Iteamlog) {
  return fetchapi<Study.Iteamlog>(api.teamaddteamlog, body)
}

export const asyncteamadminaddteamuser = function (body: { name: string | number, teamid: number }) {
  return fetchapi<[Study.Iteamuser, boolean]>(api.teamadminaddteamuser, body)
}

export const asyncteamaddteamgroup = function (body: Study.Iteamusergroup) {
  return fetchapi<Study.Iteamusergroup>(api.teamaddteamgroup, body)
}
export const asyncUpdateBatchTeamGroup = function (body: { teamid: number, teamusergroupid: number, userid: number[] }) {
  return fetchapi<Study.Iteamusergroup>(api.updateBatchTeamGroup, body)
}

export const asyncteamdelteamuser = function (body: { ID: number, teamid: number }) {
  return fetchapi<Study.Iteamuser>(api.teamdelteamuser, body)
}

export const asyncteamchangeteamuser = function (body: Study.Iteamuser) {
  return fetchapi<Study.Iteamuser>(api.teamchangeteamuser, body)
}

export const asyncdelteam = function (body: { ID: number, teamid: number }) {
  return fetchapi(api.teamdelteam, body)
}


export const asyncteamcreateteamtask = function (body: Study.Iteamtask) {
  return fetchapi(api.teamcreateteamtask, body)
}


export const asyncgetmyquestionbank = function (body: Iobj<Study.Iquestionbank>) {
  return fetchapi<Imyreq<Study.Iquestionbank>>(api.getmyquestionbank, body)
}


export const asyncgetmyquestion = function (body: Iobj<Study.Iquestion>) {
  return fetchapi<Imyreq<Study.Iquestion>>(api.getmyquestion, body)
}

export const asyncadminselectquestion = function (body: Iobj<Study.Iquestion>) {
  return fetchapi<Imyreq<Study.Iquestion>>(api.adminselectquestion, body)
}

export const asyncselectteamuserdata = function <T>(body: Iobj<T>) {
  return fetchapi<Imyreq<T>>(api.selectteamuserdata, body)
}

export const asyncdelteamtask = function (body: { ID: number }) {
  return fetchapi(api.delteamtask, body)
}

export const asyncdelnotice = function (body: { ID: number }) {
  return fetchapi(api.delnotice, body)
}
export interface IApinotice extends Study.Inotice {
  users?: number[]
}
export const asynccreateorupdatenotice = function (body: IApinotice) {
  return fetchapi(api.createorupdatenotice, body)
}

export const asyncselectnotice = function (body: Iobj<Study.Inotice>) {
  return fetchapi<Imyreq<Study.Inotice>>(api.selectnotice, body)
}

export const asyncgetmynotice = function (body?: Iobj<Study.Iusernotice>) {
  return fetchapi<{
    rows: Study.Iusernotice[],
    count: number,
    isseecount: number
  }>(api.getmynotice, body)
}

export const asyncchangemynotice = function (body: { ID: number }) {
  return fetchapi(api.changemynotice, body)
}


export const asyncteamdelnotice = function (body: { ID: number, teamid: number }) {
  return fetchapi(api.teamdelnotice, body)
}

export const asyncteamcreateorupdatenotice = function (body: IApinotice) {
  return fetchapi<Study.Inotice>(api.teamcreateorupdatenotice, body)
}

export const asyncteamselectnotice = function (body: Iobj<Study.Inotice>) {
  return fetchapi<Imyreq<Study.Inotice>>(api.teamselectnotice, body)
}

export const asyncselectactivityuser = function (body: Iobj<Study.Iactivityuser>) {
  return fetchapi<Imyreq<Study.Iactivityuser>>(api.selectactivityuser, body)
}

export const asyncdelteamgroup = function (body: { ID: number, teamid: number }) {
  return fetchapi<Imyreq<Study.Iteamusergroup>>(api.delteamgroup, body)
}


/**
 * 
 * @param body 题单ID
 * @returns 测评id
 */
export const asyncgettestid = function (body: { questionbankid: number }) {
  return fetchapi<string>(api.gettestid, body)
}

export const asyncdelquestioncomment = function (body: { ID: number }) {
  return fetchapi(api.delquestioncomment, body)
}

export const asyncchangequestioncomment = function (body: { ID: number, top: boolean }) {
  return fetchapi(api.changequestioncomment, body)
}

export const asyncselectaccepted = function (body: Iobj<Study.Iaccepted>) {
  return fetchapi<Imyreq<Study.Iaccepted>>(api.selectaccepted, body)
}

export const asyncselectquestiontestcasesuser = function (body: Iobj<Study.Iquestiontestcasesuser>) {
  return fetchapi<Imyreq<Study.Iquestiontestcasesuser>>(api.selectquestiontestcasesuser, body)
}

export const asynccreatequestiontestcasesuser = function (body: { questiontestcasesuser: Study.Iquestiontestcasesuser[] }) {
  return fetchapi(api.createquestiontestcasesuser, body)
}

export const asyncchangequestiontestcasesuser = function (body: any) {
  return fetchapi(api.changequestiontestcasesuser, body)
}

export const asyncdelquestiontestcasesuser = function (body: { ID?: number }) {
  return fetchapi(api.delquestiontestcasesuser, body)
}
export interface DF extends Study.Imatchuserquestion {
  df: number
}
export const asyncnoticeac = function (body: { activityid: number }) {
  return fetchapi<{ user: Study.Iuser, list: DF[], df?: number }[]>(api.noticeac, body)
}

export const asynccopyquestionbank = function (body: Study.Iquestionbank) {
  return fetchapi(api.copyquestionbank, body)
}

export const asyncselectpackagekey = function (body: Iobj<Alymodel.IMpackegekey>) {
  return fetchapi<Imyreq<Alymodel.IMpackegekey>>(api.selectpackagekey, body)
}
// 获取代理商课包-课程组
export const asyncSelectPackageCatebagRelation = function (body: Iobj<Alymodel.IMpackegekey>) {
  return fetchapi<Imyreq<Alymodel.PackageCatebagRelation>>(api.selectPackageCatebagRelation, body)
}

export const asyncchangeteamcoursegroup = function (body: Study.Iteamcoursegroup) {
  return fetchapi(api.changeteamcoursegroup, body)
}

export const asyncselectteamcoursegroup = function (body: Iobj<Study.Iteamcoursegroup>) {
  return fetchapi<Imyreq<Study.Iteamcoursegroup>>(api.selectteamcoursegroup, body)
}

export const asyncupdateteamcoursegroup = function (body: { teamid: number, courses: number[] }) {
  return fetchapi(api.updateteamcoursegroup, body)
}

export const asyncchangepassword = function (body: { password: string, password1: string, password2: string }) {
  return fetchapi(api.changepassword, body)
}

export type ChartApitype = {
  userquestion: Array<{ day: string, count: number }>
  userquestion2: Array<{ userid: number, count: number }>
  matchuserquestion: Array<{ userid: number, count: number }>
  matchuserquestion2: Array<{ userid: number, count: number }>
}

export const asyncselectchart = function (body: {
  teamid?: number, starttime: Date | number, endtime: Date | number, userids?: number[], timetype?: string
}) {
  return fetchapi<ChartApitype>(api.selectchart, body)
}


export const asyncselectacceptedrun = function (body: Iobj<Study.Iacceptedrun>) {
  return fetchapi<Imyreq<Study.Iacceptedrun>>(api.selectacceptedrun, body)
}

export const asyncaddaccepted = function (body: Iobj<Study.Iaccepted>) {
  return fetchapi(api.addaccepted, body)
}
export const asyncdelaccepted = function (body: { ID: number }) {
  return fetchapi(api.delaccepted, body)
}



/**
 * 团队成员排行榜
 * @param body 
 * @returns 
 */
export const asyncranking = function (body: { teamid?: number, userid?: number, formdate: Date | number | string, todate: Date | number | string, questionid?: number, questionbankid?: number }) {
  interface _IIUSER {
    count: number
    createdAt: Date
    countlength: number
    distinctquestionid: number
    resultdataarraclength: string
    resultdataarrlength: string
    resultdatacount: number
    userid: number
    resultdataarrmax: number
    比赛?: number, 题解贡献?: number, 测试点贡献?: number, 金币?: number, 测评?: number
  }
  return fetchapi<{ user: Study.Iuser[], ACrank: _IIUSER[] }>(api.ranking, body)
}

interface _N {
  AClabel: { labelid: number, count: number }[],
  ACrank: number,
  allrank: number,
  userquestion: Study.Iuserquestion[],
  Alllabel: { labelid: number, count: number }[],
  groupkuserquestion: { count: number, hover: number }[],
  ACmatch: number,
  matchquestion: Study.Imatchuserquestion[],
}

export const asyncteamuserquestion = function (body: { teamid: number, userid?: number, formdate: Date | number, todate: Date | number }) {

  return fetchapi<_N>(api.teamuserquestion, body)
}

export const asyncselectsms = function (body: Iobj<Study.Isms>) {
  return fetchapi<Imyreq<Study.Isms>>(api.selectsms, body)
}

export const asynccreatedsms = function (body: Study.Iteamuser) {
  return fetchapi(api.createdsms, body)
}
export const asyncCreatedSmsv2 = function (body: Study.Iteamuser) {
  return fetchapi(api.createdsmsv2, body)
}

export const asyncselectspecialjudge = function (body: Iobj<Study.Ispecialjudge>) {
  return fetchapi<Imyreq<Study.Ispecialjudge>>(api.selectspecialjudge, body)
}

export const asynccreateorupdatespecialjudge = function (body: Study.Ispecialjudge) {
  return fetchapi<Study.Ispecialjudge>(api.createorupdatespecialjudge, body)
}

export const asyncdelspecialjudge = function (body: { ID: number }) {
  return fetchapi(api.delspecialjudge, body)
}

export const asynccreatedorupdatematchquestion = function (body: Study.Imatchquestion) {
  return fetchapi(api.createdorupdatematchquestion, body)
}
export const asyncCreatedOrUpdateMatchQuestion = function (body: Study.Imatchquestion) {
  return fetchapi(api.createdOrUpdateMatchQuestion, body)
}

export const asyncdelmatchquestion = function (body: { ID: number }) {
  return fetchapi(api.delmatchquestion, body)
}

export type IselectstatisticsType = 'selectusercountgroupteam' | 'selectuserlasttimecountgroupteam' | 'selectuserquestiongroupteam' | 'selectuserquestionacgroupteam' | 'selectuserquestiondistinctgroupteam' | 'selectusercountgroupteams' | 'matchuser'

export const asyncselectstatistics = function (body?: { team?: number[], type: IselectstatisticsType[], from: number, to: number }) {
  return fetchapi<Record<IselectstatisticsType, Array<{ teamid: number, count: number }>>>(api.selectstatistics, body)
}

export const asynccreatedactivityuser = function (body: { teamid: number, activityid: number, phonenums: Array<string | number> }) {
  return fetchapi(api.createdactivityuser, body)
}

export const asyncgetactivityuser = function (body: { activityid: number }) {
  return fetchapi<Study.Iactivityuser>(api.getactivityuser, body)
}

export const asyncselectmatchranking = function (body: Iobj<{ activityid: number, df: number }>) {
  return fetchapi<{ matchranking: Study.Imatchranking[], user: Study.Iuser[], question: Study.Imatchquestion[] }>(api.selectmatchranking, body)
}

export const asyncteamcreateorupdateactivity = function (body: Study.Iactivity) {
  return fetchapi(api.teamcreateorupdateactivity, body)
}

export const asyncteamdelactivity = function (body: { ID: number, teamid: number }) {
  return fetchapi(api.teamdelactivity, body)
}

export const asyncteamchangematchquestion = function (body: { activityid: number, teamid: number, question: Study.Imatchquestion[] }) {
  return fetchapi(api.teamchangematchquestion, body)
}

export interface Iteamselectmatchuserquestionnbody extends Study.Imatchuserquestion {
  teamid: number,
  activityid: number
}

export const asyncteamselectmatchuserquestion = function (body: Iobj<Iteamselectmatchuserquestionnbody>) {
  return fetchapi<Imyreq<Study.Imatchuserquestion>>(api.teamselectmatchuserquestion, body)
}

export type ISIM = { users: Study.Iuser[], data: Record<string, Record<string, [string, string][]>> }

export const asyncgetsim = function (body: { activityid: number }) {
  return fetchapi<ISIM>(api.getsim, body)
}

export const asyncgetusermatchcode = function (body: { activityid: number, userid?: number, questionid?: number }) {
  return fetchapi<[string, string][]>(api.getusermatchcode, body)
}

export function asyncteamselectactivity(body?: Iobj<Study.Iactivity>) {
  return fetchapi<Imyreq<Study.Iactivity>>(api.teamselectactivity, body)
}

export function asynccheckduplicate(body: { activityid: number }) {
  return fetchapi(api.checkduplicate, body)
}

export function asyncteamcheckduplicate(body: { activityid: number, teamid: number }) {
  return fetchapi(api.teamcheckduplicate, body)
}

export function asyncgetquestiontopdf(body: { activityid?: number, questionbankid?: number }) {
  return fetchapi<Study.Iquestion[] | Study.Imatchquestion[]>(api.getquestiontopdf, body)
}

export function asyncteamselectactivityuser(body: Iobj<{ teamid: number, activityid: number }>) {
  return fetchapi<Imyreq<Study.Iactivity>>(api.teamselectactivityuser, body)
}

export function asyncteamdelactivityuser(body: { teamid: number, activityid: number, ID: number }) {
  return fetchapi(api.teamdelactivityuser, body)
}

export function asyncgetactivityduration(body: { activityid: number, isstart?: boolean }) {
  return fetchapi<{ activityendtime: Date, activitystarttime: Date }>(api.getactivityduration, body)
}

export function asyncteamselectactivitys(body?: Iobj<Study.Iactivity>) {
  return fetchapi<Imyreq<Study.Iactivity>>(api.teamselectactivitys, body)
}
// /studycode/v2/team/selectactivity 包含参赛用户
export function asyncTeamSelectActivity(body?: Iobj<Study.Iactivity>) {
  return fetchapi<Imyreq<Study.Iactivity>>(api.teamSelectActivity, body)
}

interface Iselectteamjob extends Imyreq<Study.Iteamjob> {
  question: Study.Iquestion[]
  course: Alymodel.IMcourse[]
  teamfile: Study.Iteamfile[]
}

export function asyncteamselectteamjob(body?: Iobj<Study.Iteamjob>) {
  return fetchapi<Iselectteamjob>(api.teamselectteamjob, body)
}

export function asyncteamcreatedorupdatedteamjob(body: Study.Iteamjob) {
  return fetchapi<Imyreq<Study.Iteamjob>>(api.teamcreatedorupdatedteamjob, body)
}

export function asyncteamdelteamjob(body?: Study.Iteamjob) {
  return fetchapi(api.teamdelteamjob, body)
}

export function asyncselectteam(body: Iobj<Study.Iteam>) {
  return fetchapi<Imyreq<Study.Iteam>>(api.selectteam, body)
}

export function asyncmiaoadminselectcourse(body: Iobj<Alymodel.IMcourse>) {
  return fetchapi<Imyreq<Alymodel.IMcourse>>(api.miaoadminselectcourse, body)
}

export function asyncmiaoadminselectcatebag(body: Iobj<Alymodel.IMcatebag>) {
  return fetchapi<Imyreq<Alymodel.IMcatebag>>(api.miaoadminselectcatebag, body)
}

export function asyncmiaoadminselectlession(body: Iobj<Alymodel.IMlession>) {
  return fetchapi<Imyreq<Alymodel.IMlession>>(api.miaoadminselectlession, body)
}

export function asyncmiaoadmincreatedorupdatecoursecatebag(body: Iobj<Alymodel.IMcoursecatebag>) {
  return fetchapi<Alymodel.IMcoursecatebag>(api.miaoadmincreatedorupdatecoursecatebag, body)
}

export function asyncmiaoadmindelcoursecatebag(body: Iobj<Alymodel.IMcoursecatebag>) {
  return fetchapi<Alymodel.IMcoursecatebag>(api.miaoadmindelcoursecatebag, body)
}

export function asyncmiaoadmincreatedorupdatelession(body: Iobj<Alymodel.IMlession>) {
  return fetchapi<Alymodel.IMlession>(api.miaoadmincreatedorupdatelession, body)
}

export function asyncmiaoadmindellession(body: Iobj<Alymodel.IMlession>) {
  return fetchapi<Alymodel.IMlession>(api.miaoadmindellession, body)
}

export function asyncmiaoadmincreatedorupdatecoursesection(body: Iobj<Alymodel.IMcoursesection>) {
  return fetchapi<Alymodel.IMcoursesection>(api.miaoadmincreatedorupdatecoursesection, body)
}

export function asyncmiaoadmindelcoursesection(body: Iobj<Alymodel.IMcoursesection>) {
  return fetchapi<Alymodel.IMcoursesection>(api.miaoadmindelcoursesection, body)
}

export function asyncmiaoadminselectcoursesection(body: Iobj<Alymodel.IMcoursesection>) {
  return fetchapi<Imyreq<Alymodel.IMcoursesection>>(api.miaoadminselectcoursesection, body)
}

export function asyncmiaoadmincreatedorupdatecoursecoursesection(body: Iobj<Alymodel.IMcoursecoursesection>) {
  return fetchapi<Alymodel.IMcoursecoursesection>(api.miaoadmincreatedorupdatecoursecoursesection, body)
}

export function asyncmiaoadmindelcoursecoursesection(body: Iobj<Alymodel.IMcoursecoursesection>) {
  return fetchapi<Alymodel.IMcoursecoursesection>(api.miaoadmindelcoursecoursesection, body)
}

export function asyncmiaoadminselectcoursecoursesection(body: Iobj<Alymodel.IMcoursecoursesection>) {
  return fetchapi<Imyreq<Alymodel.IMcoursecoursesection>>(api.miaoadminselectcoursecoursesection, body)
}

export function asynccreatedteamjobrelation(body: { teamid: number, list: Study.Iteamjobrelation[] }) {
  return fetchapi<Imyreq<Study.Iteamjobrelation[]>>(api.createdteamjobrelation, body)
}

export function asyncadmingetcourseforum(body: Iobj<Alymodel.IMcourseforum>) {
  return fetchapi<Imyreq<Alymodel.IMcourseforum>>(api.admingetcourseforum, body)
}

export function asyncadmindelcourseforum(body: Alymodel.IMcourseforum) {
  return fetchapi(api.admindelcourseforum, body)
}

export function asyncadminupdatecourseforum(body: Alymodel.IMcourseforum) {
  return fetchapi(api.adminupdatecourseforum, body)
}


export function asyncselectusersolution(body: Iobj<Study.Iusersolution>) {
  return fetchapi<Imyreq<Study.Iusersolution>>(api.selectusersolution, body)
}

export function asynccreatedorupdateusersolution(body: Study.Iusersolution) {
  return fetchapi(api.createdorupdateusersolution, body)
}

export function asyncdelusersolution(body: { ID: number }) {
  return fetchapi(api.delusersolution, body)
}

export function asyncgetintegral(body: { userid: number }) {
  return fetchapi<{ nums: number, type: Study.Iintegral['type'] }[]>(api.getintegral, body)
}

export function asyncselectintegral(body: Iobj<Study.Iintegral>) {
  return fetchapi<Imyreq<Study.Iintegral>>(api.selectintegral, body)
}

export function asyncdelintegral(body: { ID: number }) {
  return fetchapi(api.delintegral, body)
}

export function asynccreateorupdateintegral(body: Study.Iintegral) {
  return fetchapi(api.createorupdateintegral, body)
}

export function asyncdelactivityuser(body: { ID: number }) {
  return fetchapi(api.delactivityuser, body)
}

export function asyncselectintegrallist(body: Iobj<Studycodemodel.Iintegral>) {
  return fetchapi(api.selectintegrallist, body)
}

interface IIIselectusercharoption { count: number, day: string }


export interface Iselectuserchar {
  /**
   * 最近登录
   */
  lasttimeuser: IIIselectusercharoption[],
  /**
   * 做题
   */
  userquestion: IIIselectusercharoption[],
  /**
   * 比赛
   */
  usermatchquestion: IIIselectusercharoption[],
  /**
   * 题解
   */
  usersolution: IIIselectusercharoption[],
  /**
   * 讨论
   */
  questioncomment: IIIselectusercharoption[],
  /**
   * 注册
   */
  createuser: IIIselectusercharoption[],
  /**
   * 用户
   */
  user: IIIselectusercharoption[],
  /**
   * 比赛积分
   */
  matchintegral: IIIselectusercharoption[],
  /**
   * 练习积分
   */
  practiceintegral: IIIselectusercharoption[],
  /**
   * 金币
   */
  goldintegral: IIIselectusercharoption[],
  /**
   * 贡献
   */
  contributionintegral: IIIselectusercharoption[]
}
export function asyncselectuserchar(body: { teamid?: number, starttime?: Date, endtime?: Date, userids?: number[], timetype?: string }) {
  return fetchapi<Iselectuserchar>(api.selectuserchar, body)
}

export function asyncselecthomechar(body: { teamid?: number, starttime?: Date, endtime?: Date, userids?: number[], timetype?: string }) {
  return fetchapi<Iselectuserchar>(api.selecthomechar, body)
}


export function asyncchangematchcomment(body: IcreatematchcommentBody) {
  return fetchapi<Iselectuserchar>(api.changematchcomment, body)
}



export function asynccreatematchcomment(body: IcreatematchcommentBody) {
  return fetchapi<Iselectuserchar>(api.creatematchcomment, body)
}

interface IcreatematchcommentBody extends Study.Imatchcomment {
  text?: string
  activityname?: string
}

export function asyncdelmatchcomment(body: Study.Imatchcomment) {
  return fetchapi<Iselectuserchar>(api.delmatchcomment, body)
}

export function asyncuploadAccess(body: { teamid?: number }) {
  return fetchapi<{
    accessKeyId: string;
    accessKeySecret: string;
    expiration: string;
    securityToken: string;
  }>(api.uploadAccess, body)
}


export function asynccreateteamfile(body: Study.Iteamfile) {
  return fetchapi(api.createteamfile, body)
}


export function asyncdelectteamfile(body: Study.Iteamfile) {
  return fetchapi(api.delectteamfile, body)
}


export function asyncgetteamfile(body: Iobj<Studycodemodel.Iteamfile>) {
  return fetchapi<Imyreq<Studycodemodel.Iteamfile>>(api.getteamfile, body)
}


export function asyncgetteamflow(body: Iobj<Studycodemodel.Iteamflow>) {
  return fetchapi<Studycodemodel.Iteamflow>(api.getteamflow, body)
}

interface Iflow extends Studycodemodel.Iteamflow {
  name?: string
  teamfileid?: number
}

export function asyncupdateteamflow(body: Iobj<Iflow>) {
  return fetchapi<Studycodemodel.Iteamflow>(api.updateteamflow, body)
}

export function asyncadmingetteamfile(body: Iobj<Studycodemodel.Iteamfile>) {
  return fetchapi<Imyreq<Studycodemodel.Iteamfile>>(api.admingetteamfile, body)
}

export function asyncadmingetteamflow(body: Iobj<Studycodemodel.Iteamflow>) {
  return fetchapi<Studycodemodel.Iteamflow>(api.admingetteamflow, body)
}

export function asyncadminupdateteamflow(body: Iobj<Studycodemodel.Iteamflow>) {
  return fetchapi<Studycodemodel.Iteamflow>(api.adminupdateteamflow, body)
}

export function asynclogincodeforces(body: Study.Iuser) {
  return fetchapi<Study.Iuser>(api.logincodeforces, body)
}


export function asyncselectsignin(body: Iobj<Study.Iteamsignin>) {
  return fetchapi<Imyreq<Study.Iteamsignin>>(api.selectsignin, body)
}

export function asyncdelsigninactivity(body: Study.Isigninactivity) {
  return fetchapi<Study.Isigninactivity>(api.delsigninactivity, body)
}

export function asyncselectsigninactivity(body: Iobj<Study.Isigninactivity>) {
  return fetchapi<Imyreq<Study.Isigninactivity>>(api.selectsigninactivity, body)
}

export function asynccreatesigninactivity(body: Study.Isigninactivity) {
  return fetchapi<Study.Isigninactivity>(api.createsigninactivity, body)
}

export function asyncupdatesigninactivity(body: Study.Isigninactivity) {
  return fetchapi<Study.Isigninactivity>(api.updatesigninactivity, body)
}

export function asynccreatesignin(body: Study.Isigninactivity) {
  return fetchapi<Study.Iteamsignin>(api.createsignin, body)
}

export function asyncuserselectsignin(body: Iobj<Study.Iteamsignin>) {
  return fetchapi<Imyreq<Study.Iteamsignin>>(api.userselectsignin, body)
}


export function asyncsignin(body: Study.Iteamsignin) {
  return fetchapi<Study.Iteamsignin>(api.signin, body)
}


export function asyncuserselectsigninactivity(body: Iobj<Study.Isigninactivity>) {
  return fetchapi<Imyreq<Study.Isigninactivity>>(api.userselectsigninactivity, body)
}

export function asyncselectusersigninactivity() {
  return fetchapi<Study.Iusersigninactivity[]>(api.selectusersigninactivity)
}

export function asyncaddactivityuser(body: Study.Iactivityuser) {
  return fetchapi(api.addactivityuser, body)
}

export function asyncselectquestionlabel(body: Iobj<Study.Iquestionlabel>) {
  return fetchapi<Imyreq<Study.Iquestionlabel>>(api.selectquestionlabel, body)
}

export function asyncuserselectquestion(body: Iobj<Study.Iquestion>) {
  return fetchapi<Imyreq<Study.Iquestion>>(api.userselectquestion, body)
}

export interface CquestionALL {
  question: Study.Iquestion[],
  team: number[],
  userid: number,
  resource: boolean
}

export function asynccreatequestionall(body: CquestionALL) {
  return fetchapi<Study.Iquestion[]>(api.createquestionall, body)
}

export function asyncaddquestionbankteam(body: Study.Iquestionbankteam) {
  return fetchapi(api.addquestionbankteam, body)
}

export function asyncdelquestionbankteam(body: Study.Iquestionbankteam) {
  return fetchapi(api.delquestionbankteam, body)
}

export function asyncaddquestionteam(body: Study.Iquestionteam) {
  return fetchapi(api.addquestionteam, body)
}

export function asyncdelquestionteam(body: Study.Iquestionteam) {
  return fetchapi(api.delquestionteam, body)
}

export function asyncdelteamhome(body: Study.Iteamhome) {
  return fetchapi(api.delteamhome, body)
}

export function asynccreateorupdateteamhome(body: Study.Iteamhome) {
  return fetchapi(api.createorupdateteamhome, body)
}

export function asyncselectteamhome(body: Iobj<Study.Iteamhome>) {
  return fetchapi<Imyreq<Study.Iteamhome>>(api.selectteamhome, body)
}

export function asyncselectscience(body: { teamid?: number, starttime?: Date, endtime?: Date, userids?: number[], timetype?: string, type: string }) {
  return fetchapi(api.selectscience, body)
}

export function asyncselectmyscience(body: { teamid?: number, starttime?: Date, endtime?: Date, userids?: number[], timetype?: string }) {
  return fetchapi(api.selectmyscience, body)
}


export function asyncselectscienceteamid(body: { teamid: number, starttime?: Date, endtime?: Date, userids?: number[], timetype?: string }) {
  return fetchapi(api.selectscienceteamid, body)
}

export function asyncselectscienctuser(body: Iobj<Study.Iscienceuser>) {
  return fetchapi<Imyreq<Study.Iscienceuser>>(api.selectscienctuser, body)
}

export function asynccreatedorupdatescienceuser(body: Study.Iscienceuser) {
  return fetchapi(api.createdorupdatescienceuser, body)
}

export function asyncdelectscienceuser(body: { ID: number }) {
  return fetchapi(api.delectscienceuser, body)
}


export function asyncselectcatebags(body: Iteamobj<Alymodel.IMcatebag>) {
  return fetchapi<Imyreq<Alymodel.IMcatebag>>(api.selectcatebags, body)
}

export function asyncGetAllCourseGroup(body: Iteamobj<Alymodel.IMcatebag>) {
  return fetchapi<Imyreq<Alymodel.CourseGroup>>(api.getAllCourseGroup, body)
}

export function asyncselectcourse(body: Iteamobj<Alymodel.IMcourse>) {
  return fetchapi<Imyreq<Alymodel.IMcourse>>(api.selectcourse, body)
}
export function asyncSelectCourseLession(body: Iteamobj<Alymodel.IMcourse>) {
  return fetchapi<Imyreq<Alymodel.IMcourse>>(api.selectCourseLession, body)
}
// saas 云课堂课程配置
export function asyncselectUsercourse(body: Iteamobj<Alymodel.IMcourse>) {
  return fetchapi<{ [uid: number]: Alymodel.IMusercourse[] }>(api.selectUsercourse, body)
}
// 通过course id 获取 lession
export const asyncGetLessionByCourseid = function (data?: { cid: number }) {
  return fetchapi<[Alymodel.IMlession]>(api.getLessionByCourseid, data)
};
export const asyncGetCourseFile = function (data?: any) {
  return fetchapi<Alymodel.Ifileurl[]>(api.getCourseFile, data)
};
// 查询课程资料
export const asyncSelectCoursefile = function (data?: any) {
  return fetchapi<Alymodel.Iteachercoursefile[]>(api.selectCoursefile, data)
};
export const asyncVideoQuestion = function (data?: any) {
  return fetchapi<Alymodel.Ivideoquestion[]>(api.videoQuestion, data)
};
// 课程讨论
export const asyncSelectCourseForum = function (data: Iobj<Alymodel.IMcourseforum>) {
  return fetchapi<Imyreq<Alymodel.IMcourseforum>>(api.selectCourseForum, data)
}
export const asyncCreatedCourseForum = function (data: Alymodel.IMcourseforum & { catebag: string, coursename: string, userphonenum: string }) {
  return fetchapi(api.createdCourseForum, data)
}
export const asyncDelCourseForum = function (data: { ID: number }) {
  return fetchapi(api.delCourseForum, data)
}
// 获取视频信息
export const asyncgetvideoInfo = function (data?: any) {
  return fetchapi(api.videoInfo, data)
};
// 查询视频调整
export const asyncselectWhitepoint = function (data?: any) {
  return fetchapi(api.selectWhitepoint, data)
};
// 记录观看日志
export const asyncCreatedWatchVideo = function (data?: any) {
  return fetchapi(api.createdWatchVideo, data)
};

// 查看课程-课件
export const asyncOssUpload8 = function (data?: any) {
  return fetchapi<any>(api.ossUpload8, data)
};
export const asyncInquireusertotpdataid9 = function (data?: any) {
  return fetchapi<any>(api.inquireUsertotpdataid9, data)
};

export function asyncaddUsercourse(body: Iteamobj<Alymodel.IMcourse>) {
  return fetchapi<Imyreq<Alymodel.IMcourse>>(api.addUsercourse, body)
}
export function asyncAdminAddUsercourse(body: Iteamobj<Alymodel.IMcourse>) {
  return fetchapi<Imyreq<Alymodel.IMcourse>>(api.adminAddUsercourse, body)
}

export function asyncdeleteUsercourse(body: Iteamobj<Alymodel.IMcourse>) {
  return fetchapi<Imyreq<Alymodel.IMcourse>>(api.deleteUsercourse, body)
}

export function asyncadmingetuser(body: Study.Iuser) {
  return fetchapi<Study.Iuser>(api.admingetuser, body)
}

export function asyncSendSmsRequest(body: Studycodemodel.Isms) {
  return fetchapi(api.SendSmsRequest, body)
}


export interface IquerySmsTemplateListRequest {
  "templateCode": string,
  "auditStatus": string,
  "outerTemplateType": number,
  "templateContent": string,
  "templateName": string,
  "templateType": number,
  "orderId": string,
}
export function asyncquerySmsTemplateListRequest() {
  return fetchapi<IquerySmsTemplateListRequest[]>(api.querySmsTemplateListRequest)
}

export function asyncgettuyaorganize(body: Iobj<TuyaiotModel.ITorganize>) {
  return fetchapi<Imyreq<TuyaiotModel.ITorganize>>(api.gettuyaorganize, body)
}

export function asyncgettuyaorganizesys(body: Iobj<TuyaiotModel.ITorganize>) {
  return fetchapi<Imyreq<TuyaiotModel.ITorganize>>(api.gettuyaorganizesys, body)
}

export function asynccreateaorganize(body: TuyaiotModel.ITorganize) {
  return fetchapi(api.createaorganize, body)
}

export function asyncgettuyaiotdevice(body: Iobj<TuyaiotModel.ITdevice>) {
  return fetchapi<Imyreq<TuyaiotModel.ITdevice>>(api.gettuyaiotdevice, body)
}

export function asynccreatedevice(body: TuyaiotModel.ITdevice) {
  return fetchapi(api.createdevice, body)
}
export function asyncdeldevice(body: TuyaiotModel.ITdevice) {
  return fetchapi(api.deldevice, body)
}
export function asyncdelaorganize(body: TuyaiotModel.ITdevice) {
  return fetchapi(api.delaorganize, body)
}

export function asyncgetzhimahuuer(body: { unionid: string }) {
  return fetchapi<Imyreq<Studycodemodel.Izhimahuuser>>(api.getzhimahuuer, body)
}
export function asynccreatedzhimahuuer(body: Studycodemodel.Izhimahuuser) {
  return fetchapi(api.createdzhimahuuer, body)
}
export function asyncdelzhimahuuer(body: { ID: number }) {
  return fetchapi(api.delzhimahuuer, body)
}

export function asyncgetintegralreward(body?: Iobj<Studycodemodel.Iintegralreward>) {
  return fetchapi<Imyreq<Studycodemodel.Iintegralreward>>(api.getintegralreward, body)
}
export function asynccreateintegralreward(body: Studycodemodel.Iintegralreward) {
  return fetchapi(api.createintegralreward, body)
}
export function asyncdelintegralreward(body: { ID: number }) {
  return fetchapi(api.delintegralreward, body)
}

export function asyncgetintegralrewarduser(body?: Iobj<Studycodemodel.Iintegralrewarduser>) {
  return fetchapi<Imyreq<Studycodemodel.Iintegralrewarduser>>(api.getintegralrewarduser, body)
}

export function asynccreateintegralrewarduser(body: Studycodemodel.Iintegralrewarduser) {
  return fetchapi(api.createintegralrewarduser, body)
}

export function asyncselectzhimahuuser(body?: Iobj<Studycodemodel.Izhimahuuser>) {
  return fetchapi<Imyreq<Studycodemodel.Izhimahuuser>>(api.selectzhimahuuser, body)
}

export function asyncupdateintegralrewarduser(body: Studycodemodel.Iintegralrewarduser) {
  return fetchapi(api.updateintegralrewarduser, body)
}

export function asyncdelintegralrewarduser(body: Studycodemodel.Iintegralrewarduser) {
  return fetchapi(api.delintegralrewarduser, body)
}

export function asyncrunactivity(body: { ID: number, iscatch?: boolean, isinfo?: boolean, iso2?: boolean, userid?: number[] }) {
  return fetchapi(api.runactivity, body)
}
export function asyncTeamRunActivity(body: { teamid: number, ID: number, iscatch?: boolean, isinfo?: boolean, iso2?: boolean, userid?: number[] }) {
  return fetchapi(api.teamRunActivity, body)
}

export function asyncrunranking(body: Studycodemodel.Iintegralrewarduser) {
  return fetchapi(api.runranking, body)
}

interface Iteamjobrelation extends Studycodemodel.Iteamjobrelation {
  teamid?: number
}

export function asyncselectteamjobrelation(body: Iobj<Iteamjobrelation>) {
  return fetchapi<Imyreq<Studycodemodel.Iteamjobrelation>>(api.selectteamjobrelation, body)
}
// 任务完成情况
export function asyncselectteamjobrelations(body: Iobj<Iteamjobrelation>) {
  return fetchapi<Studycodemodel.Iteamjobrelation[]>(api.selectteamjobrelations, body)
}

export function asyncgetteamjob(body: Iobj<Studycodemodel.Iteamjob>) {
  return fetchapi<Imyreq<Studycodemodel.Iteamjob>>(api.getteamjob, body)
}

export function asyncsynchronous(body: { activityid: number, t: boolean }) {
  return fetchapi(api.synchronous, body)
}

export function asyncgetcustomerservice(body?: Iobj<Studycodemodel.Icustomerservice>) {
  return fetchapi<Studycodemodel.Icustomerservice[]>(api.getcustomerservice, body)
}

export function asyncupdatecustomerservice(body: Studycodemodel.Icustomerservice) {
  return fetchapi(api.updatecustomerservice, body)
}

export function asyncdelcustomerservice(body: { ID: number }) {
  return fetchapi(api.delcustomerservice, body)
}

export function asyncteamresetpassword(body: { ID: number, teamid: number }) {
  return fetchapi(api.teamresetpassword, body)
}

export function asynccopyquestion(body: Study.Iquestion) {
  return fetchapi(api.copyquestion, body)
}

export function asyncselectvipdata(body: Iobj<Study.Ivipdata>) {
  return fetchapi<Imyreq<Studycodemodel.Ivipdata>>(api.selectvipdata, body)
}

export function asyncupdateviplist(body: Study.Iviplist) {
  return fetchapi(api.updateviplist, body)
}

export function asyncselectviplist(body: Iobj<Study.Iviplist>) {
  return fetchapi<Imyreq<Studycodemodel.Iviplist>>(api.selectviplist, body)
}

export function asyncupdelviplist(body: Study.Iviplist) {
  return fetchapi(api.delviplist, body)
}

export function asyncupdatevipdataviplist(body: Study.Ivipdataviplist) {
  return fetchapi(api.updatevipdataviplist, body)
}

export function asyncselectvipdataviplist(body: Iobj<Study.Iviplist>) {
  return fetchapi<Imyreq<Studycodemodel.Ivipdataviplist>>(api.selectvipdataviplist, body)
}

export function asyncdelvipdataviplist(body: Study.Ivipdataviplist) {
  return fetchapi(api.delvipdataviplist, body)
}

export function asyncupdateuservip(body: Study.Iuservip) {
  return fetchapi(api.updateuservip, body)
}

export function asyncselectuservip(body: Iobj<Study.Iuservip>) {
  return fetchapi<Imyreq<Studycodemodel.Iuservip>>(api.selectuservip, body)
}

export function asyncdeluservip(body: Study.Iuservip) {
  return fetchapi(api.deluservip, body)
}

// 权限
export function asynccreateteamrole(body: Studycodemodel.Iteamrole) {
  return fetchapi<Studycodemodel.Iteamrole>(api.createteamrole, body)
}
export function selectteamrole(body: Studycodemodel.Iteamrole) {
  return fetchapi<{ rows: Studycodemodel.Iteamrole[], count: number }>(api.selectteamrole, body)
}
export function delteamrole(body: Studycodemodel.Iteamrole) {
  return fetchapi<Studycodemodel.Iteamrole>(api.delteamrole, body)
}

// 赛后总结
export function asyncSelectmatchsummary(body: Iobj<Studycodemodel.Imatchsummary>) {
  return fetchapi<Imyreq<Studycodemodel.Imatchsummary>>(api.selectmatchsummary, body)
}
export function asyncGetmatchsummary(body: Studycodemodel.Imatchsummary) {
  return fetchapi<Studycodemodel.Imatchsummary>(api.getmatchsummary, body)
}
export function asyncCreatematchsummary(body: Studycodemodel.Imatchsummary) {
  return fetchapi<Studycodemodel.Imatchsummary>(api.creatematchsummary, body)
}

// vip组别
export function asyncSelectVipAuthority(body?: Iobj<Study.Ivipauthority>) {
  return fetchapi<{ rows: Study.Ivipauthority[], count: number }>(api.selectvipauthority, body)
}
export function asyncUpdateVipAuthority(body?: Iobj<Study.Ivipauthority>) {
  return fetchapi<Study.Ivipauthority>(api.updatevipauthority, body)
}
export function asyncDelVipAuthority(body: IID) {
  return fetchapi<Study.Ivipauthority>(api.delvipauthority, body)
}
// vip 标签-题目 
export function asyncSelectQuestionSelectedLabel(body?: Iobj<Study.Iquestionselectedlabel>) {
  return fetchapi<{ rows: Study.Iquestionselectedlabel[], count: number }>(api.selectQuestionSelectedLabel, body)
}
export function asyncUpdateQuestionSelectedLabel(body?: Iobj<Study.Iquestionselectedlabel>) {
  return fetchapi<Study.Iquestionselectedlabel>(api.updateQuestionSelectedLabel, body)
}
export function asyncDelQuestionSelectedLabel(body: IID) {
  return fetchapi<Study.Iquestionselectedlabel>(api.delQuestionSelectedLabel, body)
}
// vip 组别-标签 
export function asyncSelectVipAuthorityLabel(body?: Iobj<Study.Ivipauthoritylabel>) {
  return fetchapi<{ rows: Study.Ivipauthoritylabel[], count: number }>(api.selectVipAuthorityLabel, body)
}
export function asyncUpdateVipAuthorityLabel(body?: Iobj<Study.Ivipauthoritylabel>) {
  return fetchapi<Study.Ivipauthoritylabel>(api.updateVipAuthorityLabel, body)
}
export function asyncDelVipAuthorityLabel(body: IID) {
  return fetchapi<Study.Ivipauthoritylabel>(api.delVipAuthorityLabel, body)
}
// 用户-组别

// 题库分组
export function asyncSelectquestionblack(body?: Iobj<Study.Iquestionblack>) {
  return fetchapi<{ rows: Study.Iquestionblack[], count: number }>(api.selectquestionblack, body)
}
export function asyncDDelquestionblack(body: IID) {
  return fetchapi<{ rows: Study.Iquestionblack }>(api.delquestionblack, body)
}
export function asyncUpdatequestionblack(body?: Iobj<Study.Iquestionblack>) {
  return fetchapi<Study.Iquestionblack>(api.updatequestionblack, body)
}
export function asyncAddquestionblacklist(body?: Iobj<Study.Iquestionblack>) {
  return fetchapi<Study.Iquestionblack>(api.addquestionblacklist, body)
}
// AI
export function asyncSelectmodel(body?: Iobj<Study.Ichatmodel>) {
  return fetchapi<{ rows: Study.Ichatmodel[], count: number }>(api.selectmodel, body)
}
export function asyncCreateorupdatemodel(body?: Study.Ichatmodel) {
  return fetchapi<Study.Ichatmodel>(api.createorupdatemodel, body)
}
export function asyncDelmodel(body: IID) {
  return fetchapi<Study.Ichatmodel>(api.delmodel, body)
}
export function asyncSelectchatprompt(body?: Iobj<Study.Ichatprompt>) {
  return fetchapi<{ rows: Study.Ichatprompt[], count: number }>(api.selectchatprompt, body)
}
export function asyncCreateorupdatechatprompt(body?: Study.Ichatprompt) {
  return fetchapi<Study.Ichatprompt>(api.createorupdatechatprompt, body)
}
export function asyncDelchatprompt(body: IID) {
  return fetchapi<Study.Ichatprompt>(api.delchatprompt, body)
}
// AI题解
export function asyncUserSelectacaicontent(body?: Iobj<Study.Iacaicontent>) {
  return fetchapi<{ rows: Study.Iacaicontent[], count: number }>(api.userselectacaicontent, body)
}
export function asyncSelectacaicontent(body?: Iobj<Study.Iacaicontent>) {
  return fetchapi<{ rows: Study.Iacaicontent[], count: number }>(api.selectacaicontent, body)
}
export function asyncDelacaicontent(body: IID) {
  return fetchapi<Study.Iacaicontent>(api.delacaicontent, body)
}
export function asyncCreateaccoder(body?: { questionid?: [number | undefined, number | undefined], questionbankid?: number | undefined }) {
  return fetchapi<Study.Iacaicontent>(api.createaccoder, body)
}

// 创建ai题目标签任务
export function asyncAutoquestionlabel(body?: any) {
  return fetchapi<any>(api.autoquestionlabel, body)
}
// 创建ai题目难度任务
export function asyncAutoquestiondiff(body?: any) {
  return fetchapi<any>(api.autoquestiondiff, body)
}
// AI比赛分析
export function asyncCreateActivitysummarize(body?: { activityid?: number | undefined }) {
  return fetchapi<any>(api.createActivitysummarize, body)
}
export function asyncGetactivitysummarize(body: any) {
  return fetchapi<any>(api.getactivitysummarize, body)
}
// AI比赛成员分析
export function asyncCreateActivityusersummarize(body?: { activityid?: number | undefined }) {
  return fetchapi<any>(api.createActivityusersummarize, body)
}
export function asyncGetactivityusersummarize(body: any) {
  return fetchapi<any>(api.getactivityusersummarize, body)
}
// AI学生周数据分析
export function asyncGetActivityUserWeeklySummary(body?: any) {
  return fetchapi<any>(api.getactivityuserweeklysummary, body)
}
export function asyncAutoUserWeeklySummary(body?: { year: number, week: number }) {
  return fetchapi<any>(api.autoUserWeeklySummary, body)
}


export function asyncCreateOrUpdateLiveUrl(body: Study.Iliveurl) {
  return fetchapi<Study.Iliveurl>(api.createorupdateliveurl, body)
}

export function asyncSelectLiveUrl(body?: Iobj<Study.Iliveurl>) {
  return fetchapi<{ rows: Study.Iliveurl[], count: number }>(api.selectliveurl, body)
}

export function asyncgetteamfiledwonload(body: Iobj<Studycodemodel.Iteamfiledwonload>) {
  return fetchapi<Imyreq<Studycodemodel.Iteamfile>>(api.getteamfiledwonload, body)
}

export function asyncgetmatchjob(body: { activityid: number }) {
  return fetchapi<{ [key: string]: number }>(api.getmatchjob, body)
}

export function asyncselectdockerteamid() {
  return fetchapi<number[]>(api.selectdockerteamid)
}

export function asyncchangedockerteamid(body: { teamid: number[] }) {
  return fetchapi(api.changedockerteamid, body)
}

export function asynccreateuserquestioncreatetime(body: { teamId: number, averagePerDay: number, startDate: Date, difficulties: number[], endDate: Date }) {
  return fetchapi(api.createuserquestioncreate, body)
}

export function asynccreateuserquestionstart(body: { teskId: number }) {
  return fetchapi<{ isduplicate: boolean }>(api.createuserquestionstart, body)
}

export function asynccreateuserquestiondelete(body: { teskId: number }) {
  return fetchapi(api.createuserquestiondelete, body)
}

interface LogEntry {
  action: LogAction;
  detail: Record<string, unknown>;
  operator?: LogActor;
  at: string;
}

type LogAction = 'create' | 'start' | 'delete' | 'complete' | 'failed';

interface LogActor {
  id?: number;
  name?: string;
  ip?: string;
}

export function asynccreateuserquestionlogs(body: { limit?: number }) {
  return fetchapi<LogEntry>(api.createuserquestionlogs, body)
}
